package com.nineclock.sign.controller;

import com.nineclock.api.sign.SignControllerApi;
import com.nineclock.common.entity.Result;
import com.nineclock.sign.dto.SignAllUserDTO;
import com.nineclock.sign.dto.SignDTO;
import com.nineclock.sign.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nineclock.api.sign.SignControllerApi;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.sign.dto.SignPCListDTO;
import com.nineclock.sign.service.SignListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class SignController implements SignControllerApi {

    @Autowired
    SignService signService;

    @Autowired
    SignListService signListService;

    @Override
    @PostMapping("/insert")
    public Result sign(SignDTO signDTO) {
        signService.sign(signDTO);
        return Result.success();
    }

    @Override
    @GetMapping("/getDayCount")
    public Result<Integer> examine() {
        Integer integer = signService.examine();
        return Result.success(integer);
    }


    /**
     * APP:查询本月签到记录
     *
     * @param dateStr
     * @return
     */
    @Override
    @GetMapping("/pagingSignCurrentUserByMonth")
    public Result<List<SignDTO>> pagingSignCurrentUserByMonth(@RequestParam String dateStr) {
        List<SignDTO> signDTOs = signService.pagingSignCurrentUserByMonth(dateStr);
        return Result.success(signDTOs);
    }

    /**
     * APP: 获取团队员工打卡列表
     *
     * @param dateStr
     * @return
     */
    @Override
    @GetMapping("/listSignAllUser")
    public Result<List<SignAllUserDTO>> listSignAllUser(@RequestParam String dateStr) {
        List<SignAllUserDTO> result = signService.listSignAllUser(dateStr);
        return Result.success(result);
    }

    @Override
    @GetMapping("/sign")
    public Result<PageResult<SignPCListDTO>> querySignList(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            String startTime, String endTime) {

        PageResult<SignPCListDTO> pcListDTOPage = signListService.querySignList(page, pageSize, startTime, endTime);

        return Result.success(pcListDTOPage);
    }
}
